﻿<?php

include_once('Common.php');

class JobController extends D_Controller {
	
	function init() {
		set_time_limit(8889889);
		$this->setLayout ('main', 'itwork');
		$this -> lo_obj = new Location();
		$this -> work_obj = new Workstyle();
		$this -> job_obj = new Job();
		$this -> jcat_obj = new Jobcategory();
	}

	function findAction(){
		$workstyle = $this -> work_obj -> find_all();
		$jobcategory = $this -> jcat_obj -> find_all();
		$location = $this -> lo_obj -> find_all();
		$this -> view -> location = $location;
		$this -> view -> workstyle = $workstyle;
		$this -> view -> jobcategory = $jobcategory;


		$request = $this -> _request -> getParams('formRegis');
		$param = array();
		if(!empty($request['category'])){
			if(gettype($request['category']) == "string"){
				if($request['category'] != 'null')	$param['category'] = array($request['category']);
			}else{
				$param['category'] = $request['category'];
			}
		}
		if(!empty($request['location'])){
			if(gettype($request['location']) == "string"){
				if($request['location'] != 'null')	$param['location'] = array($request['location']);
			}else{
					$param['location'] = $request['location'];
			}
		
		}
		if(!empty($request['workstyle'])){
			if(gettype($request['workstyle']) == "string"){
				if($request['workstyle'] != 'null')	$param['workstyle'] = array($request['workstyle']);
			}else{
					$param['workstyle'] = $request['workstyle'];
			}
		}
		if(isset($request['keyword']) && $request['keyword'] != ""){
			$param['keyword'] = $request['keyword'];
		}
		$data = $this -> job_obj -> find_job_by_condition($param);
		$paginator = Zend_Paginator::factory($data);
		$currentPage = 1;
		$i = $this->_getParam('page',1);
		if(!empty($i))
		{
				$currentPage = $i;
		}
		$paginator->setItemCountPerPage(COUNT_PER_PAGE)
							->setPageRange(3)
							->setCurrentPageNumber($currentPage);
		$this -> view -> job = $paginator;
		$this -> view -> param = $param;
	}
	function newAction(){
		$data = $this -> job_obj -> find_new_job();
		$paginator = Zend_Paginator::factory($data);
		$currentPage = 1;
		$i = $this->_getParam('page',1);
		if(!empty($i))
		{
				$currentPage = $i;
		}
		$paginator->setItemCountPerPage(COUNT_PER_PAGE)
							->setPageRange(3)
							->setCurrentPageNumber($currentPage);
		$this -> view -> job = $paginator;
	}
	function viewAction() {
			$id= $this->_request->getParam('id');
			if(isset($id)){
				$data = $this -> job_obj -> fetchOne(array('Job_ID' => $id));
				$this -> view -> info = $data;
			}
	}

}

?>